{% extends 'wxchat/wxbase.html' %}{% load static %}
{% block extra %}
    <style>
    .height{
        height: 1.47058824em;
        line-height: 1.47058824;
    }

    </style>
{% endblock extra%}
{% block container %}
<div class="weui-panel">
    <div class="weui-panel__hd header_bottom">
         <div class="weui-flex">
            <div><a href="javascript:window.history.back(-1)"><i class="icon iconfont icon-jiantou3 gray " ></i></a></div>
            <div class="weui-flex__item" style="text-align: center;"><span class="detail_title">宠物登记</span></div>
            <div ><a href="{% url 'dog-index' %}?next={{ request.get_full_path }}"><i class="icon iconfont icon-shouye2 pink r" ></i></a></div>
        </div>
    </div>
    <div class="weui-panel__bd">
        <form action="" method="post" enctype="multipart/form-data" onsubmit="showing()">{% csrf_token %}
        <div class="weui-cells weui-cells_form cells_top" id="uploader">
            <input type="hidden" id="input_type" name = "input_type" value="{{ input_type|default:'' }}">
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">{{ form.name.label }}:</label></div>
                <div class="weui-cell__bd">{{ form.name }}</div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label for="" class="weui-label">{{ form.sex.label }}:</label></div>
                <div class="weui-cell__bd">{{ form.sex }}</div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label for="" class="weui-label">{{ form.category.label }}:</label>
                </div>
                <div class="weui-cell__bd">{{ form.category }}</div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label for="" class="weui-label">{{ form.birthdate.label }}:</label>
                </div>
                <div class="weui-cell__bd">{{ form.birthdate }}</div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label for="" class="weui-label">{{ form.type.label }}:</label></div>
                <div class="weui-cell__bd">{{ form.type }}</div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label for="" class="weui-label">{{ form.color.label }}:</label></div>
                <div class="weui-cell__bd">{{ form.color }}</div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label for="" class="weui-label">{{ form.sterilization.label }}:</label></div>
                <div class="weui-cell__bd">{{ form.sterilization }}</div>
            </div>
             <div class="weui-cell">
                <div class="weui-cell__hd"><label for="" class="weui-label">{{ form.vaccine.label }}:</label></div>
                <div class="weui-cell__bd">{{ form.vaccine }}</div>
            </div>
{#            <div class="weui-cell">#}
{#                <div class="weui-cell__hd"><label for="" class="weui-label">{{ form.parasite.label }}:</label></div>#}
{#                <div class="weui-cell__bd">{{ form.parasite }}</div>#}
{#            </div>#}
{#            <div class="weui-cell">#}
{#                <div class="weui-cell__hd"><label for="" class="weui-label">{{ form.illness.label }}:</label></div>#}
{#                <div class="weui-cell__bd">{{ form.illness }}</div>#}
{#            </div>#}
{#            <div class="weui-cell">#}
{#                <div class="weui-cell__hd"><label for="" class="weui-label">{{ form.infection.label }}:</label></div>#}
{#                <div class="weui-cell__bd">{{ form.infection }}</div>#}
{#            </div>#}
            <div class="weui-cell">
                <div class="weui-cell__hd"><label for="" class="weui-label">{{ form.owner.label }}:</label></div>
                <div class="weui-cell__bd">{{ form.owner }}</div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">{{ form.picture.label }}:</label></div>
                <div class="weui-cell__bd">
                    <div class="weui-uploader">
                         <div class="weui-uploader__bd">
                             <ul class="weui-uploader__files" id="uploaderFiles">
                                 {% if form.picture.value is not None %}
                                     {% get_media_prefix  as prefix %}
                                     <li class="weui-uploader__file" style="background-image:url('{{ prefix }}{{ form.picture.value}}')"></li>
                                 {% endif %}
                             </ul>
                             <div class="weui-uploader__input-box">
                                 <input accept="image/*" class="weui-uploader__input" id="id_picture" name="picture" type="file" {% if form.picture.value is  None %} required="" {% endif %}>
                             </div>
                         </div>
                    </div>
                </div>
                <div class="weui-cell__ft">
                    <div class="weui-cells__tips"></div>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label for="" class="weui-label">{{ form.telephone.label }}:</label></div>
                <div class="weui-cell__bd">
                    {{ form.telephone }}
                </div>
            </div>
        <div class="weui-btn-area">
            <button type="submit" name="submit" class="weui-btn weui-btn_primary" >提交</button>
            {% if form.instance.id %}
            <button type="button" id="btn_del" data-item="{{ form.instance.id }}" class="weui-btn  weui-btn_plain-primary" >删除</button>
            {% endif %}
        </div>
        </form>
    </div>
</div>

{% endblock container %}
{% block bottomjs %}

    {{ block.super }}
    <script type="application/javascript">
    $(function(){
        $("#btn_del").on("click", function(){
            weui.confirm('真的要删除吗？', function() {
                    var params ={
                      pet_id: $("#btn_del").attr("data-item"),
                      input_type: $("#input_type").val(),
                      csrfmiddlewaretoken:'{{ csrf_token }}',
                    }
                    $.ajax({
                          type: 'POST',
                          url: '{% url "foster-pet-del" %}',
                          dataType: 'json',
                          data: params,
                          timeout: 5000,
                          success: function(data){
                              if(data.return_code == "SUCCESS"){
                                  if(data.input_type == "hosting")
                                        window.location.href = "{% url 'hosting-pet-list' %}";
                                  else {
                                      window.location.href = "{% url 'foster-pet-list' %}";
                                  }
                              }
                              else{
                                   weui.alert('删除失败');
                              }

                          },
                          error: function(error){
                                 weui.alert('删除失败');
                          }
                    });
                },
                function() {
                        console.log("fail");
                }
            );


        })

    });

    </script>
{% endblock bottomjs %}
